﻿// Example header text. Can be configured in the options.
using vtech_formBase;
using System;
using vtech_frameWorks.Exceptions;
using System.Data;

namespace PharmacySystem.BusinessObject.Department
{
    public partial class frmAddDepartment : frmAdd
    {
        public delegate void Add();
        public event Add OnAdd = null;
        protected override void FireEvent()
        {
            if (this.OnAdd != null)
            {
                this.OnAdd();
            }
        }

        public frmAddDepartment()
        {
            this.InitializeComponent();
        }

        protected override bool CheckControl()
        {
            bool flag = false;
            try
            {
                this.errorProvider.Dispose();
                if (this.txtDepartmentCode.Text == "")
                {
                    this.errorProvider.SetError(this.txtDepartmentCode, "Bạn chưa nhập mã đơn vị. Xin vui lòng kiểm tra lại");
                    flag = false;
                }
                else
                {
                    if (this.txtDepartmentName.Text == "")
                    {
                        this.errorProvider.SetError(this.txtDepartmentName, "Bạn chưa nhập tên đơn vị. Xin vui lòng kiểm tra lại");
                        flag = false;
                    }
                    else
                    {
                        flag = true;
                    }
                }
            }
            catch (Exception ex)
            {
                ClsInformation.Error(ex.Message);
                flag = false;
            }
            return flag;
        }

        protected override void Insert()
        {
            try
            {
                using (DsDepartment dsDepartment = new DsDepartment())
                {
                    ClsDepartmentBS obj = new ClsDepartmentBS();
                    DataRow drow = dsDepartment.DtBusinessObject.NewRow();
                    dsDepartment.DtBusinessObject.Rows.Add(drow);
                    drow["Code"] = this.txtDepartmentCode.Text.Trim();
                    drow["Name"] = this.txtDepartmentName.Text.Trim();
                    drow["Description"] = this.txtDescription.Text.Trim();
                    obj.DoInsert(dsDepartment.DtBusinessObject);
                }
            }
            catch (Exception ex)
            {
                ClsInformation.Error(ex.ToString());
            }
        }
    }
}